Release 10.1A: OpenEdge Development:
Progress 4GL Handbook
Using the AppBuilder to generate function definitions
If you want to build a procedure file of any size with a number of internal entries, whether internal procedures or functions, you should definitely use the AppBuilder to create it for you. The AppBuilder generates most of the supporting statements you’ve just read about here for user-defined functions, and provides a separate code section for each to make it easy to maintain your procedures.
![]()
To see how to define a function in the AppBuilder and what it does for you:
- Go into the Section Editor for the new
h-OrderWin.wprocedure.- Select Functions from the Section drop-down list. This message appears:
![]()
- Answer Yes. The New Function dialog box appears:
![]()
- Enter the function name dataColor and specify
INTEGERfor the Returns value, then click OK.- Enter this definition for the function:
The AppBuilder has generated the
FUNCTION dataColorheader syntax along with theRETURNSphrase, a placeholderRETURNstatement and theEND FUNCTIONstatement. You fill in the parameter definitions where the comment prompts you to do that. The function accepts two dates asINPUTparameters, calculates the difference between them (which is an integer value), and returns an integer value representing the appropriate background color for the second date. This is color code 12, 13, or 14, representing colors red, purple, and yellow, depending on how far apart the two dates are and whether either of them is undefined.- Go into the main block and add a line of code to invoke the function and assign the
BGCOLORattribute for background color to the date field when the row is displayed:
- Save
h-OrderWin.w, then Runh-CustOrderWin6.w.There are only a few Orders where the ShipDate is later than the PromiseDate.
- To find a few, enter a New State of GA for Georgia.
- Click the Next button to get to Customer 3.
- Select Order number 160 in the browse and click the Order Detail button to run
h-OrderWin.w. You see the field is displayed in red, as it should be:
![]()
- Select Order number 189, which has no ShipDate at all, and click Order Detail:
![]()
The ShipDate shows up in red here also because it has the Unknown value (
?).Think about the code you just wrote. You defined an implementation for a function called
dateColor, which goes to the bottom of theh-OrderWin.wprocedure file, along with any internal procedures. Then you added a line of code to the main block that references the function.The main block is above the function in the procedure, so why didn’t Progress complain that there was no declaration for the function? The reason is that the AppBuilder generated it for you.
- Go into the Compile
Code Preview window for
h-OrderWin.wand search for dateColor (use the CTRL+F sequence for Find).You’ll see the function prototype in one of the header sections that comes before the main block or any other executable code:
Thus, the AppBuilder not only helps you generate the header for the function code itself, but it also generates a prototype for you and organizes all the code into sections where you can easily inspect and maintain individual entries.
The AppBuilder copies the parameter definitions from your function header just as you entered it in the Section Editor so you cannot remove them from the function header, even though in a hand-coded procedure file you could define them in the prototype and leave them out of the function header itself.
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |